<template>
  <div class="top">
    <el-row :gutter="20" type="flex" justify="space-between">
      <el-col :span="6">
        <span class="hint">说明：目前支持学科和关键字条件筛选</span>
      </el-col>
      <el-col :span="6">
        <el-row type="flex" justify="end">
          <el-button type="success" size="small" @click="$router.push('/questions/new')">
            <i class="el-icon-edit"></i>
            新增试题</el-button
          >
        </el-row>
      </el-col>
    </el-row>
    <!-- 表单 -->
    <el-form :model="formDate">
      <el-row :gutter="24" type="flex" class="row-bg">
        <el-col :span="6" type="text">
          <el-form-item label-width="80px" label="学科">
            <el-select
              v-model="formDate.subject"
              placeholder="请选择"
              size="small"
              @change="subChange"
            >
              <el-option
                v-for="item in subsimpleList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" type="text">
          <el-form-item label-width="80px" label="二级目录">
            <el-select
              v-model="formDate.catalogID"
              placeholder="请选择"
              size="small"
              @change="secondLeveChange"
            >
              <el-option
                v-for="item in secondLevelDirectory"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" type="text">
          <el-form-item label-width="80px" label="标签">
            <el-select
              v-model="formDate.tags"
              placeholder="请选择"
              size="small"
            >
              <el-option
                v-for="item in tags"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" type="text">
          <el-form-item label-width="80px" label="题目备注">
            <el-input
              size="small"
              placeholder="根据题干搜索"
              v-model="formDate.keyword"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24" type="flex" class="row-bg">
        <el-col :span="6" type="text">
          <el-form-item label-width="80px" label="试题类型">
            <el-select
              v-model="formDate.questionType"
              placeholder="请选择"
              size="small"
            >
              <el-option
                v-for="item in questionType"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" type="text">
          <el-form-item label-width="80px" label="难度">
            <el-select
              v-model="formDate.difficulty"
              placeholder="请选择"
              size="small"
            >
              <el-option
                v-for="item in difficulty"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" type="text">
          <el-form-item label-width="80px" label="方向">
            <el-select
              v-model="formDate.direction"
              placeholder="请选择"
              size="small"
            >
              <el-option
                v-for="(item, index) in direction"
                :key="index"
                :label="item"
                :value="index"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" type="text">
          <el-form-item label-width="80px" label="录入人">
            <el-select
              v-model="formDate.creator"
              placeholder="请选择"
              size="small"
            >
              <el-option
                v-for="item in peopleList"
                :key="item.id"
                :label="item.username"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24" type="flex" class="row-bg">
        <el-col :span="6" type="text">
          <el-form-item label-width="80px" label="题目备注">
            <el-input size="small" v-model="formDate.remarks"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6" type="text">
          <el-form-item label-width="80px" label="企业简称">
            <el-input size="small" v-model="formDate.enterpriseID"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="6" size="small">
          <el-form-item label-width="80px" label="城市">
            <el-select
              style="width: 48%; display: inline-block"
              v-model="formDate.province"
              placeholder="请选择"
              size="small"
              @change="provincesChange"
            >
              <el-option
                v-for="(item, index) in provinces"
                :key="index"
                :label="item"
                :value="item"
              >
              </el-option>
            </el-select>

            <el-select
              v-model="formDate.citys"
              collapse-tags
              style="width: 48%; float: right"
              placeholder="请选择"
              size="small"
            >
              <el-option
                v-for="(item, index) in cityss"
                :key="index"
                :label="item"
                :value="index"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" size="small">
          <el-row type="flex" justify="end">
            <el-button size="mini" @click="btnCanel">清除</el-button>
            <el-button type="primary" size="mini" @click="SearchList"
              >搜索</el-button
            >
          </el-row>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
// 学科
import { simple } from "@/api/hmmm/subjects.js";
// 二级目录
import { simple as secondLevelSimple } from "@/api/hmmm/directorys.js";
// 标签
import { simple as tagsSimple } from "@/api/hmmm/tags.js";
// 难度
import { difficulty, questionType, direction } from "@/api/hmmm/constants.js";
// 录入人
import { list as peopleList } from "@/api/base/users.js";
// 城市
import { provinces, citys } from "@/api/hmmm/citys.js";

export default {
  name: "qq",
  data() {
    return {
      formDate: {
        subjectID: "", //学科
        catalogID: "", //二级目录
        tags: [], //标签
        keyword: "", //题目备注
        questionType: [], //试题类型
        difficulty: [], //难度
        direction: [], //方向
        creator: [], //录入人
        remarks: "", //题目备注
        enterpriseID: "", //企业简称
        province: "",
        city: [], //城市
      },
      subsimpleList: [], //学科
      secondLevelDirectory: [], //二级
      tags: [], //标签
      questionType, //试题类型
      difficulty, //难度
      direction, //方向
      peopleList, //录入人
      provinces: provinces(),
      cityss: [],
    };
  },
  created() {
    this.subsimple();
    this.crpeopleList();
  },
  methods: {
    async subsimple() {
      let { data } = await simple();
      this.subsimpleList = data;
    },
    // 学科目录修改触发二级目录
    async subChange(val) {
      this.formDate.subjectID = val;
      let { data } = await secondLevelSimple({ subjectID: val });
      let { data: tagData } = await tagsSimple({ subjectID: val });
      this.secondLevelDirectory = data;
      this.tags = tagData;
    },

    async secondLeveChange(val) {
      // this.formDate.secondLevelDirectory = val
      // console.log(data)
    },

    async crpeopleList() {
      let { data } = await peopleList();
      this.peopleList = data.list;
    },
    provincesChange(val) {
      this.cityss = citys(val);
    },
    // 清除
    btnCanel() {
      this.formDate = {
        subjectID: "", //学科
        catalogID: "", //二级目录
        tags: "", //标签
        keyword: "", //题目备注
        questionType: "", //试题类型
        difficulty: "", //难度
        direction: "", //方向
        creator: "", //录入人
        remarks: "", //题目备注
        enterpriseID: "", //企业简称
        province: "",
        city: "", //城市
      };
      this.$emit("clearlist");
    },
    // 搜索功能
    SearchList() {
      this.$emit("searchhh", this.formDate);
    },
  },
};
</script>

<style lang='less' scoped>
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.el-form .row-bg {
  background-color: #fff;
}

.row-bg {
  // padding: 10px 0;
  margin: 0;
  height: 51px;
}
.hint {
  font-size: 12px;
  color: pink;
}
.top {
  margin-bottom: 15px;
}
// .el_input_w {
//   width: 75%;
// }
// .el-form-item__label {
//   width: 80px;
// }
.el-select {
  display: block;
}

.el-form-item__label {
  width: 80px;
}
</style>
